﻿using Microsoft.EntityFrameworkCore;

namespace WpfApp2.model
{
    internal class QcsConfigDbContext : DbContext
    {
        //public QcsConfigDbContext():base("MyConnetion")
        //{
        //}

        public QcsConfigDbContext()
        {
        }

        //protected override void OnModelCreating(DbModelBuilder modelBuilder)
        //{
        //    try
        //    {
        //        var init = new SqliteCreateDatabaseIfNotExists<QcsConfigDbContext>(modelBuilder);
        //        Database.SetInitializer(init);
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;

        //    }
        //}

        protected override void OnConfiguring(DbContextOptionsBuilder options)
        {
            //Create the connection string

            var connectionString = "Data Source=QcsConfigDb.db";

            options.UseSqlite(connectionString);

            //Database.EnsureCreated();

            //Add Log for Sqlite
            //  options.EnableSensitiveDataLogging();
            //  options.LogTo(LogInfo);
            // Create a new SqliteConnection
            //var connection = new SqliteConnection(connectionString);

            //// Open the connection
            //connection.Open();

            //// Configure the connection
            //using (var command = connection.CreateCommand())
            //{
            //    command.CommandText = "PRAGMA journal_mode = DELETE;";
            //    command.ExecuteNonQuery();
            //}

            //// Configure the options to use this connection
            //options.UseSqlite(connection);
        }

        public DbSet<pc> pcs { get; set; }
        public DbSet<rack> racks { get; set; }

        public DbSet<chassis> chassiss { get; set; }

        public DbSet<slot> slots { get; set; }
    }
}